﻿--[[	$Id: watchFrame.lua 2420 2011-12-16 07:34:34Z sdkyron@gmail.com $	]]

local dummy = caelLib.dummy

local nextline = 1

WatchFrame:ClearAllPoints()
WatchFrame:SetHeight(caelLib.scale(600))
WatchFrame:SetPoint("TOPRIGHT", "UIParent", "TOPRIGHT", caelLib.scale(-5), caelLib.scale(-5))
--WatchFrameCollapseExpandButton:Hide()

WatchFrame.ClearAllPoints = dummy
WatchFrame.SetPoint = dummy
--WatchFrameCollapseExpandButton.Show = dummy

WatchFrameTitle:SetFont(caelMedia.fonts.NORMAL, 11)

hooksecurefunc("WatchFrame_Update", function()
	for i = nextline, 50 do
		line = _G["WatchFrameLine"..i]
		if line then
			line.text:SetFont(caelMedia.fonts.NORMAL, 9)
			line.dash:SetFont(caelMedia.fonts.NORMAL, 9)
			line.text:SetSpacing(2)
		else
			nextline = i
			break
		end
	end

	for i = 1, WATCHFRAME_MAXQUESTS do
		local button = _G["WatchFrameItem"..i]
		if button and not InCombatLockdown() then
			button:SetScale(0.75)

			button:SetNormalTexture(caelMedia.files.buttonNormal)
			button:SetPushedTexture(caelMedia.files.buttonPushed)

			_G["WatchFrameItem"..i.."IconTexture"]:SetTexCoord(0.08, 0.92, 0.08, 0.92)
		end
	end
end)

local ZoneChange = function(zone)
	local _, instanceType = IsInInstance()
	if instanceType == "arena" or UnitExists("boss1") then
		if not WatchFrame.collapsed then
			WatchFrame_CollapseExpandButton_OnClick(WatchFrame_CollapseExpandButton)
		end
	elseif WatchFrame.collapsed then
		WatchFrame_CollapseExpandButton_OnClick(WatchFrame_CollapseExpandButton)
	end
end

WatchFrame:HookScript("OnEvent", function(self, event)
	local zone = GetRealZoneText()
	if zone and zone ~= "" then
		return ZoneChange(zone)
	end
end)

for _, event in next, {
	"WORLD_MAP_UPDATE",
	"PLAYER_ENTERING_WORLD",
	"ZONE_CHANGED_NEW_AREA",
	"INSTANCE_ENCOUNTER_ENGAGE_UNIT",
} do
	WatchFrame:RegisterEvent(event)
end